<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
  <meta name="baidu-site-verification" content="code-kg5UjKJZM2" />
   
  <meta name="keywords" content="活,炼" />
   
  <meta name="description" content="shimmerjordan" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Py爬虫+基于echart可视化csv数数据 |  丛烨-shimmerjordan
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
  
<link rel="stylesheet" href="/css/custom.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'G-Q0DT8B8VJW', 'auto');
ga('send', 'pageview');

</script>



  
<script>
var _hmt = _hmt || [];
(function() {
	var hm = document.createElement("script");
	hm.src = "https://hm.baidu.com/hm.js?6d06f826e125297d4ce0fa7a1449328e";
	var s = document.getElementsByTagName("script")[0]; 
	s.parentNode.insertBefore(hm, s);
})();
</script>


<link rel="alternate" href="/atom.xml" title="丛烨-shimmerjordan" type="application/atom+xml">
</head>

</html>

	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
	<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-Py爬虫-基于echart可视化csv数数据"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Py爬虫+基于echart可视化csv数数据
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/06/19/pyecharts_tour_statistic/" class="article-date">
  <time datetime="2020-06-18T16:04:06.000Z" itemprop="datePublished">2020-06-19</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Python%E5%88%9D%E7%BA%A7%E5%BA%94%E7%94%A8/">Python初级应用</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">3.7k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">17 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>​        前面一篇文章谈及了Python基于<code>matplotlib</code>模块的csv数据可视化，这篇文章从更广度的数据角度，结合Python爬虫并利用<code>pyecharts</code>这个更优雅的数据可视化模块，对从网络爬取的数据集进行可视化处理。由于Echart的可操作性，最终生成的可视化图像以html的形式展现以供检阅，文中也会贴出静态预览图。</p>
<span id="more"></span>
<h1 id="1-爬取目标分析"><a href="#1-爬取目标分析" class="headerlink" title="1 爬取目标分析"></a>1 爬取目标分析</h1><h2 id="1-1-分析目标url"><a href="#1-1-分析目标url" class="headerlink" title="1.1 分析目标url"></a>1.1 分析目标url</h2><p>​        这里选用了<a href="[http://piao.qunar.com">去哪儿旅行</a>作为爬虫的目标，因为观察到点击”门票“后搜索相应关键词，例如热门景点，跳转URL为<code>http://piao.qunar.com/ticket/list.htm?keyword=辽宁&amp;region=&amp;from=mpl_search_suggest&amp;page=&#123;&#125;</code>， 进一步分析可知，该url的结构为<code>http://piao.qunar.com/ticket/list.htm?keyword=搜索地点&amp;region=&amp;from=mpl_search_suggest&amp;page=页数</code>，这里既然搜索热门景点可用，那么就使用该关键词进行爬虫，只需要进行页码参数的调整即可。</p>
<h2 id="1-2-分析页面元素"><a href="#1-2-分析页面元素" class="headerlink" title="1.2 分析页面元素"></a>1.2 分析页面元素</h2><p>​        进入开发者面板后使用元素选择器可以看到在如图的class下便是页面中每条记录数据的显示文字了，例如下图中的”上海·上海·浦东新区“这个地址属性便在<code>&lt;span class=&quot;area&quot;&gt;</code>标签下显示：</p>
<p><img src="https://s1.ax1x.com/2020/06/19/NM8eGq.jpg" alt="NM8eGq.jpg"></p>
<p>​        进一步的，我们可以在例如<code>&lt;div class=&quot;intro color999&quot;&gt;</code>等标签内识别到介绍等相关信息，经过分析，这里我们提取出来的信息包括了景点名称、级别、所在区域、起步价、销售量、热度、地址、经纬度、标语、详情网址。这里的经纬度在项目初期是计划使用百度API根据获取的地址信息进行获取，因此项目的展示需要百度API的支持。但后来无意发现，经纬度其实本网页html中自带，因此似乎白费百度API了。网页内自涵的经纬度如下所示：</p>
<p><img src="https://s1.ax1x.com/2020/06/19/NM3zGt.jpg" alt="NM3zGt.jpg"></p>
<h1 id="2-爬取数据"><a href="#2-爬取数据" class="headerlink" title="2 爬取数据"></a>2 爬取数据</h1><p>​        这里发现这个网站居然是基于http协议而且没有反爬机制的，因此直接采用request爬取即可，在爬取过程中我曾经因为网络不好被拒绝请求，一度以为是被反爬关了小黑屋，就在我要用scrapy解决反爬问题的时候，我换了个网络环境，神奇的解决了这个棘手的问题。这里使用<code>xpath</code>进行内容的匹配，比正则好用许多。以下便是爬取内容的函数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">getList</span>():</span><br><span class="line">    place = <span class="string">&#x27;热门景点&#x27;</span></span><br><span class="line">    url = <span class="string">&#x27;http://piao.qunar.com/ticket/list.htm?keyword=&#x27;</span>+ place +<span class="string">&#x27;&amp;region=&amp;from=mpl_search_suggest&amp;page=&#123;&#125;&#x27;</span></span><br><span class="line">    i = <span class="number">1</span></span><br><span class="line">    sightlist = []</span><br><span class="line">    <span class="keyword">while</span> i &lt; <span class="number">400</span>:</span><br><span class="line">        page = getPage(url.<span class="built_in">format</span>(i)) <span class="comment">#这里调用了getPage函数获取了网页数据</span></span><br><span class="line">        selector = etree.HTML(page.text)</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">&#x27;正在爬取第&#x27;</span>, <span class="built_in">str</span>(i), <span class="string">&#x27;页景点信息&#x27;</span>)</span><br><span class="line">        i += <span class="number">1</span></span><br><span class="line">        informations = selector.xpath(<span class="string">&#x27;//div[@class=&quot;result_list&quot;]/div&#x27;</span>)</span><br><span class="line">        <span class="keyword">for</span> inf <span class="keyword">in</span> informations: <span class="comment">#获取必要信息</span></span><br><span class="line">            sight_name = inf.xpath(<span class="string">&#x27;./div/div/h3/a/text()&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            sight_level = inf.xpath(<span class="string">&#x27;.//span[@class=&quot;level&quot;]/text()&#x27;</span>)</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sight_level):</span><br><span class="line">                sight_level = sight_level[<span class="number">0</span>].replace(<span class="string">&#x27;景区&#x27;</span>,<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                sight_level = <span class="number">0</span></span><br><span class="line">            sight_area = inf.xpath(<span class="string">&#x27;.//span[@class=&quot;area&quot;]/a/text()&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            <span class="comment"># print(sight_area)</span></span><br><span class="line">            sight_hot = inf.xpath(<span class="string">&#x27;.//span[@class=&quot;product_star_level&quot;]//span/text()&#x27;</span>)[<span class="number">0</span>].replace(<span class="string">&#x27;热度 &#x27;</span>,<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">            sight_add = inf.xpath(<span class="string">&#x27;.//p[@class=&quot;address color999&quot;]/span/text()&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            sight_add = re.sub(<span class="string">&#x27;地址：|（.*?）|\(.*?\)|，.*?$|\/.*?$&#x27;</span>,<span class="string">&#x27;&#x27;</span>,<span class="built_in">str</span>(sight_add))</span><br><span class="line"></span><br><span class="line">            sight_slogen = inf.xpath(<span class="string">&#x27;.//div[@class=&quot;intro color999&quot;]/text()&#x27;</span>)</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sight_slogen):</span><br><span class="line">                sight_slogen = inf.xpath(<span class="string">&#x27;.//div[@class=&quot;intro color999&quot;]/text()&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                sight_slogen = <span class="string">&quot;null&quot;</span></span><br><span class="line">            sight_price = inf.xpath(<span class="string">&#x27;.//span[@class=&quot;sight_item_price&quot;]/em/text()&#x27;</span>)</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sight_price):</span><br><span class="line">                sight_price = sight_price[<span class="number">0</span>]</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                i = <span class="number">0</span></span><br><span class="line">                <span class="keyword">break</span></span><br><span class="line">            sight_soldnum = inf.xpath(<span class="string">&#x27;.//span[@class=&quot;hot_num&quot;]/text()&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            sight_point = inf.xpath(<span class="string">&#x27;./@data-point&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            sight_url = inf.xpath(<span class="string">&#x27;.//h3/a[@class=&quot;name&quot;]/@href&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">            sightlist.append([sight_name,sight_level,sight_area,<span class="built_in">float</span>(sight_price),<span class="built_in">int</span>(sight_soldnum),<span class="built_in">float</span>(sight_hot),sight_add.replace(<span class="string">&#x27;地址：&#x27;</span>,<span class="string">&#x27;&#x27;</span>),sight_point,sight_slogen,sight_url])</span><br><span class="line">        time.sleep(<span class="number">15</span>)</span><br><span class="line">    <span class="keyword">return</span> sightlist</span><br></pre></td></tr></table></figure>
<p>这里爬取的信息包括景点名称、级别、所在区域、起步价、销售量、热度、地址、经纬度、标语、详情网址。本项目实际并未完全使用，全部数据存储在csv文件中，再开发可用性高（实际上谁会去用呢？）</p>
<p>当然，有很多景点存在无销量、无星级、无介绍等情况，这里都在爬取的过程中使用了条件判断，如果为空就赋值为空或者0，这就是缺省值的处理。也可以引用上篇文章中的基于<code>sklearn</code>的缺省值处理方法，这里仿佛犯不着。</p>
<p>另一方面，地址的匹配使用<code>re.sub()</code>去除冗余信息，这里不赘述。这里使用了<code>pandas</code>库进行爬取数据的csv文件存储：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">listToExcel</span>(<span class="params"><span class="built_in">list</span>,name</span>):</span><br><span class="line">    df = pd.DataFrame(<span class="built_in">list</span>,columns=[<span class="string">&#x27;景点名称&#x27;</span>,<span class="string">&#x27;级别&#x27;</span>,<span class="string">&#x27;所在区域&#x27;</span>,<span class="string">&#x27;起步价&#x27;</span>,<span class="string">&#x27;销售量&#x27;</span>,<span class="string">&#x27;热度&#x27;</span>,<span class="string">&#x27;地址&#x27;</span>,<span class="string">&#x27;经纬度&#x27;</span>,<span class="string">&#x27;标语&#x27;</span>,<span class="string">&#x27;详情网址&#x27;</span>])</span><br><span class="line">    df.to_csv(name + <span class="string">&quot;.csv&quot;</span>, sep=<span class="string">&#x27;,&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>由于项目后期直接使用了爬取的经纬度，这里不需要借助API转换地址为经纬度，这里也给出这部分代码留作学习备份：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">getBaiduGeo</span>(<span class="params">sightlist,name</span>):</span><br><span class="line">    ak = <span class="string">&#x27;密钥&#x27;</span></span><br><span class="line">    headers = &#123;</span><br><span class="line">    <span class="string">&#x27;User-Agent&#x27;</span> :<span class="string">&#x27;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">    address = 地址</span><br><span class="line">    url = <span class="string">&#x27;http://api.map.baidu.com/geocoder/v2/?address=&#x27;</span> + address  + <span class="string">&#x27;&amp;output=json&amp;ak=&#x27;</span> + ak</span><br><span class="line">    json_data = requests.get(url = url).json()</span><br><span class="line">    json_geo = json_data[<span class="string">&#x27;result&#x27;</span>][<span class="string">&#x27;location&#x27;</span>]</span><br></pre></td></tr></table></figure>
<p>观察获取的json文件，location中的数据和百度api所需要的json格式基本是一样，还需要将景点销量加入到json文件中，最后将整理好的json文件输出到本地文件中。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">getBaiduGeo</span>(<span class="params">sightlist,name</span>):</span><br><span class="line">    ak = <span class="string">&#x27;密钥&#x27;</span></span><br><span class="line">    headers = &#123;</span><br><span class="line">    <span class="string">&#x27;User-Agent&#x27;</span> :<span class="string">&#x27;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">list</span> = sightlist</span><br><span class="line">    bjsonlist = []</span><br><span class="line">    ejsonlist1 = []</span><br><span class="line">    ejsonlist2 = []</span><br><span class="line">    num = <span class="number">1</span></span><br><span class="line">    <span class="keyword">for</span> l <span class="keyword">in</span> <span class="built_in">list</span>:</span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            <span class="keyword">try</span>:</span><br><span class="line">                <span class="keyword">try</span>:</span><br><span class="line">                    address = l[<span class="number">6</span>]</span><br><span class="line">                    url = <span class="string">&#x27;http://api.map.baidu.com/geocoder/v2/?address=&#x27;</span> + address  + <span class="string">&#x27;&amp;output=json&amp;ak=&#x27;</span> + ak</span><br><span class="line">                    json_data = requests.get(url = url).json()</span><br><span class="line">                    json_geo = json_data[<span class="string">&#x27;result&#x27;</span>][<span class="string">&#x27;location&#x27;</span>]</span><br><span class="line">                <span class="keyword">except</span> KeyError,e:</span><br><span class="line">                    address = l[<span class="number">0</span>]</span><br><span class="line">                    url = <span class="string">&#x27;http://api.map.baidu.com/geocoder/v2/?address=&#x27;</span> + address  + <span class="string">&#x27;&amp;output=json&amp;ak=&#x27;</span> + ak</span><br><span class="line">                    json_data = requests.get(url = url).json()</span><br><span class="line">                    json_geo = json_data[<span class="string">&#x27;result&#x27;</span>][<span class="string">&#x27;location&#x27;</span>]</span><br><span class="line">            <span class="keyword">except</span> KeyError,e:</span><br><span class="line">                    address = l[<span class="number">2</span>]</span><br><span class="line">                    url = <span class="string">&#x27;http://api.map.baidu.com/geocoder/v2/?address=&#x27;</span> + address  + <span class="string">&#x27;&amp;output=json&amp;ak=&#x27;</span> + ak</span><br><span class="line">                    json_data = requests.get(url = url).json()</span><br><span class="line">                    json_geo = json_data[<span class="string">&#x27;result&#x27;</span>][<span class="string">&#x27;location&#x27;</span>]</span><br><span class="line">        <span class="keyword">except</span> KeyError,e:</span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        json_geo[<span class="string">&#x27;count&#x27;</span>] = l[<span class="number">4</span>]/<span class="number">100</span></span><br><span class="line">        bjsonlist.append(json_geo)</span><br><span class="line">        ejson1 = &#123;l[<span class="number">0</span>] : [json_geo[<span class="string">&#x27;lng&#x27;</span>],json_geo[<span class="string">&#x27;lat&#x27;</span>]]&#125;</span><br><span class="line">        ejsonlist1 = <span class="built_in">dict</span>(ejsonlist1,**ejson1)</span><br><span class="line">        ejson2 = &#123;<span class="string">&#x27;name&#x27;</span> : l[<span class="number">0</span>],<span class="string">&#x27;value&#x27;</span> : l[<span class="number">4</span>]/<span class="number">100</span>&#125;</span><br><span class="line">        ejsonlist2.append(ejson2)</span><br><span class="line">        <span class="built_in">print</span> <span class="string">&#x27;正在生成第&#x27;</span> + <span class="built_in">str</span>(num) + <span class="string">&#x27;个景点的经纬度&#x27;</span></span><br><span class="line">        num +=<span class="number">1</span></span><br><span class="line">    bjsonlist =json.dumps(bjsonlist)</span><br><span class="line">    ejsonlist1 = json.dumps(ejsonlist1,ensure_ascii=<span class="literal">False</span>)</span><br><span class="line">    ejsonlist2 = json.dumps(ejsonlist2,ensure_ascii=<span class="literal">False</span>)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./points.json&#x27;</span>,<span class="string">&quot;w&quot;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(bjsonlist)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./geoCoordMap.json&#x27;</span>,<span class="string">&quot;w&quot;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(ejsonlist1)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./data.json&#x27;</span>,<span class="string">&quot;w&quot;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(ejsonlist2)</span><br></pre></td></tr></table></figure>
<p>本项目最终采用了以下方式输出json数据文件：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">datatojson</span>(<span class="params">sightlist</span>):  <span class="comment">#直接生成json数据</span></span><br><span class="line">    bjsonlist = []</span><br><span class="line">    ejsonlist1 = []</span><br><span class="line">    ejsonlist2 = []</span><br><span class="line">    num = <span class="number">1</span></span><br><span class="line">    <span class="keyword">for</span> l <span class="keyword">in</span> sightlist:</span><br><span class="line">        json_geo = &#123;&#125;</span><br><span class="line">        p = <span class="string">&#x27;(.*?),(.*?)$&#x27;</span></span><br><span class="line">        geo = re.findall(p,l[<span class="number">7</span>])[<span class="number">0</span>]</span><br><span class="line">        json_geo[<span class="string">&#x27;lat&#x27;</span>] = geo[<span class="number">1</span>]</span><br><span class="line">        json_geo[<span class="string">&#x27;count&#x27;</span>] = l[<span class="number">4</span>]/<span class="number">100</span></span><br><span class="line">        json_geo[<span class="string">&#x27;lng&#x27;</span>] = geo[<span class="number">0</span>]</span><br><span class="line">        bjsonlist.append(json_geo)</span><br><span class="line"><span class="comment">#        print(&#x27;正在生成第&#x27;, str(num), &#x27;个景点的经纬度&#x27;)</span></span><br><span class="line">        ejson1 = &#123;l[<span class="number">0</span>] : [geo[<span class="number">0</span>],geo[<span class="number">1</span>]]&#125;</span><br><span class="line">        ejsonlist1 = <span class="built_in">dict</span>(ejsonlist1,**ejson1)</span><br><span class="line">        ejson2 = &#123;<span class="string">&#x27;name&#x27;</span> : l[<span class="number">0</span>],<span class="string">&#x27;value&#x27;</span> : l[<span class="number">4</span>]/<span class="number">100</span>&#125;</span><br><span class="line">        ejsonlist2.append(ejson2)</span><br><span class="line">        num +=<span class="number">1</span></span><br><span class="line">    bjsonlist =json.dumps(bjsonlist)</span><br><span class="line">    ejsonlist1 = json.dumps(ejsonlist1, ensure_ascii=<span class="literal">False</span>)</span><br><span class="line">    ejsonlist2 = json.dumps(ejsonlist2, ensure_ascii=<span class="literal">False</span>)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./points.json&#x27;</span>,<span class="string">&quot;w&quot;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(bjsonlist)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./geoCoordMap.json&#x27;</span>,<span class="string">&quot;w&quot;</span>, encoding=<span class="string">&#x27;utf-8&#x27;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(ejsonlist1)</span><br><span class="line">    <span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;./data.json&#x27;</span>,<span class="string">&quot;w&quot;</span>, encoding=<span class="string">&#x27;utf-8&#x27;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(ejsonlist2)</span><br></pre></td></tr></table></figure>
<p>​        这里生成的三个json文件，一个是给百度地图api引入用的，另俩个是给echartsMap引入用的。</p>
<h1 id="3-数据可视化"><a href="#3-数据可视化" class="headerlink" title="3 数据可视化"></a>3 数据可视化</h1><h2 id="3-1-热力图生成"><a href="#3-1-热力图生成" class="headerlink" title="3.1 热力图生成"></a>3.1 热力图生成</h2><p>​        将前文所述的百度地图api示例中的源代码复制到解释器中，添加密钥（需要自己申请），保存为html文件，打开就可以看到和官网上一样的显示效果。echarts需要在实例页面，点击页面右上角的EN切换到英文版，然后点击download demo下载完整源代码。</p>
<p>​        根据<a target="_blank" rel="noopener" href="http://www.jb51.net/article/36678.htm">html导入json文件</a>修改网页源码，导入json文件。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">#百度地图api示例代码中各位置修改部分</span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;http://libs.baidu.com/jquery/2.0.0/jquery.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    $.<span class="title function_">getJSON</span>(<span class="string">&quot;points.json&quot;</span>, <span class="keyword">function</span>(<span class="params">data</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> points = data;</span></span><br><span class="line"><span class="language-javascript">        script中原有函数；</span></span><br><span class="line"><span class="language-javascript">        &#125;);</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span>       </span><br></pre></td></tr></table></figure>
<p>​        此时直接打开baiduMap.html或者echartMap.html均不会正常显示，F12后得知服务器异常。因此这里需要创建一个服务器才能在本地显示（这两个只能运行于服务器），这里进入需要打开的html文件目录，首先将需要打开的html文件重命名为<code>index.html</code>，然后在此目录下调用控制台。python3环境下需使用<code>python -m  http.server</code>开启本地服务器，收取到成功开启的提示后在浏览器中打开<a target="_blank" rel="noopener" href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a>，即可浏览index.html。在控制台中Ctrl+C关闭本地服务器。</p>
<p>​    baiduMap.html以及echartMap.html的预览效果依次如下所示：</p>
<p><img src="https://s1.ax1x.com/2020/06/19/NM6i9K.jpg" alt="NM6i9K.jpg"></p>
<p><img src="https://s1.ax1x.com/2020/06/19/NM6F1O.jpg" alt="NM6F1O.jpg"></p>
<p>​    这是爬取了400页，每页15条数据后的结果，因此有些许简陋。进一步的数据完善下次一定，下次一定！</p>
<h2 id="3-2-数据进一步可视化"><a href="#3-2-数据进一步可视化" class="headerlink" title="3.2 数据进一步可视化"></a>3.2 数据进一步可视化</h2><p>​        在此基础上，为了进一步分析数据，进一步针对一些特性绘制Echarts：</p>
<h3 id="3-2-1-绘制热门景点前20的柱状图"><a href="#3-2-1-绘制热门景点前20的柱状图" class="headerlink" title="3.2.1 绘制热门景点前20的柱状图"></a>3.2.1 绘制热门景点前20的柱状图</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 绘制热门景点前20的柱状echart</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">first_20_echart</span>():</span><br><span class="line">    <span class="comment"># 设置行名</span></span><br><span class="line">    columns = name_list</span><br><span class="line">    <span class="comment"># 设置数据</span></span><br><span class="line">    data1 = top_list</span><br><span class="line">    <span class="comment"># 设置柱状图的主标题与副标题</span></span><br><span class="line">    bar = pyecharts.Bar(title=<span class="string">&quot;热门景点前20的柱状图&quot;</span>)</span><br><span class="line"></span><br><span class="line">    bar.add(<span class="string">&quot;热度&quot;</span>, columns, data1, mark_line=[<span class="string">&quot;average&quot;</span>],xaxis_rotate=<span class="number">30</span>,  mark_point=[<span class="string">&quot;max&quot;</span>, <span class="string">&quot;min&quot;</span>])</span><br><span class="line">    <span class="comment"># 生成本地文件（默认为.html文件）</span></span><br><span class="line">    bar.render(<span class="string">&#x27;first_20_echart.html&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p><img src="https://s1.ax1x.com/2020/06/19/NMytfK.jpg" alt="NMytfK.jpg"></p>
<h2 id="3-2-2-绘制主要城市景点数漏斗图"><a href="#3-2-2-绘制主要城市景点数漏斗图" class="headerlink" title="3.2.2 绘制主要城市景点数漏斗图"></a>3.2.2 绘制主要城市景点数漏斗图</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 绘制主要城市热门景点数漏斗图</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">nation_hotspot_echart</span>():</span><br><span class="line"></span><br><span class="line">    fl = pyecharts.Funnel(<span class="string">&quot;主要城市热门景点数&quot;</span>, <span class="string">&quot;2020年6月18日 22:36:24&quot;</span>, title_pos=<span class="string">&#x27;left&#x27;</span>, width=<span class="number">1400</span>, height=<span class="number">700</span>)</span><br><span class="line">    fl.add(<span class="string">&quot;景点数&quot;</span>, add_key, add_value, is_label_show=<span class="literal">True</span>, label_formatter=<span class="string">&#x27;&#123;b&#125;&#123;c&#125;&#x27;</span>, label_pos=<span class="string">&#x27;outside&#x27;</span>)</span><br><span class="line">    fl.render(<span class="string">&#x27;nation_hotspot_echart.html&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p><img src="https://s1.ax1x.com/2020/06/19/NMyJFx.jpg" alt="NMyJFx.jpg"></p>
<h2 id="3-2-3-绘制top20城市的3A、4A、5A景区数"><a href="#3-2-3-绘制top20城市的3A、4A、5A景区数" class="headerlink" title="3.2.3 绘制top20城市的3A、4A、5A景区数"></a>3.2.3 绘制top20城市的3A、4A、5A景区数</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 绘制top20城市的3A、4A、5A景区数堆叠柱形图</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">nA_spot_echart</span>():</span><br><span class="line">    <span class="comment"># 设置行名</span></span><br><span class="line">    columns = add_key</span><br><span class="line">    <span class="comment"># 设置数据</span></span><br><span class="line">    data1 = level_3a</span><br><span class="line">    data2 = level_4a</span><br><span class="line">    data3 = level_5a</span><br><span class="line">    <span class="comment"># 设置柱状图的主标题与副标题</span></span><br><span class="line">    bar = pyecharts.Bar(title=<span class="string">&quot;top20城市的3A、4A、5A景区数&quot;</span>)</span><br><span class="line"></span><br><span class="line">    bar.add(<span class="string">&quot;3A景区数&quot;</span>, columns, data1, mark_line=[<span class="string">&quot;average&quot;</span>], xaxis_rotate=<span class="number">30</span>, mark_point=[<span class="string">&quot;max&quot;</span>, <span class="string">&quot;min&quot;</span>], is_stack=<span class="literal">True</span>)</span><br><span class="line">    bar.add(<span class="string">&quot;4A景区数&quot;</span>, columns, data2, mark_line=[<span class="string">&quot;average&quot;</span>], xaxis_rotate=<span class="number">30</span>, mark_point=[<span class="string">&quot;max&quot;</span>, <span class="string">&quot;min&quot;</span>], is_stack=<span class="literal">True</span>)</span><br><span class="line">    bar.add(<span class="string">&quot;5A景区数&quot;</span>, columns, data3, mark_line=[<span class="string">&quot;average&quot;</span>], xaxis_rotate=<span class="number">30</span>, mark_point=[<span class="string">&quot;max&quot;</span>, <span class="string">&quot;min&quot;</span>], is_stack=<span class="literal">True</span>)</span><br><span class="line">    <span class="comment"># 生成本地文件（默认为.html文件）</span></span><br><span class="line">    bar.render(<span class="string">&#x27;nA_spot_echart.html&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p><img src="https://s1.ax1x.com/2020/06/19/NMyBmd.jpg" alt="NMyBmd.jpg"></p>
<h3 id="3-2-4-绘制哪里去得起极坐标图"><a href="#3-2-4-绘制哪里去得起极坐标图" class="headerlink" title="3.2.4 绘制哪里去得起极坐标图"></a>3.2.4 绘制哪里去得起极坐标图</h3><p>这里采用了与前面热力图导入Echart一样的方式，利用html导入：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">style</span>=<span class="string">&quot;height: 100%&quot;</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">body</span> <span class="attr">style</span>=<span class="string">&quot;height: 100%; margin: 0&quot;</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;container&quot;</span> <span class="attr">style</span>=<span class="string">&quot;height: 100%&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts/dist/echarts.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts-stat/dist/ecStat.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts/dist/extension/dataTool.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts/map/js/china.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts/map/js/world.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://api.map.baidu.com/api?v=2.0&amp;ak=9hmPUqXOhGLfg8xyqzWQ9C21jU7ILXxR&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;https://gcore.jsdelivr.net/npm/echarts/dist/extension/bmap.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> dom = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;container&quot;</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> myChart = echarts.<span class="title function_">init</span>(dom);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> app = &#123;&#125;;</span></span><br><span class="line"><span class="language-javascript">option = <span class="literal">null</span>;</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> data = [</span></span><br><span class="line"><span class="language-javascript">    [<span class="number">30.0</span>, <span class="number">499.0</span>, <span class="number">156.23</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">55.0</span>, <span class="number">388.0</span>, <span class="number">147.99</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">3.5</span>, <span class="number">338.0</span>, <span class="number">106.75</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">20.0</span>, <span class="number">308.0</span>, <span class="number">75.93</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">20.0</span>, <span class="number">298.0</span>, <span class="number">33.88</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">0.3</span>, <span class="number">298.0</span>, <span class="number">84.17</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">30.0</span>, <span class="number">268.0</span>, <span class="number">117.67</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">72.0</span>, <span class="number">258.0</span>, <span class="number">165.0</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">72.0</span>, <span class="number">244.9</span>, <span class="number">179.79</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">37.3</span>, <span class="number">225.0</span>, <span class="number">102.16</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">28.0</span>, <span class="number">210.0</span>, <span class="number">110.83</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">69.0</span>, <span class="number">208.0</span>, <span class="number">138.5</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">63.8</span>, <span class="number">199.0</span>, <span class="number">140.93</span>],</span></span><br><span class="line"><span class="language-javascript">	[<span class="number">0.6</span>, <span class="number">188.0</span>, <span class="number">94.3</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">91.9</span>, <span class="number">185.0</span>, <span class="number">135.97</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">0.8</span>, <span class="number">170.0</span>, <span class="number">92.67</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">45.0</span>, <span class="number">168.0</span>, <span class="number">80.25</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">135.0</span>, <span class="number">160.0</span>, <span class="number">147.5</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">60.0</span>, <span class="number">160.0</span>, <span class="number">108.82</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">10.0</span>, <span class="number">140.0</span>, <span class="number">58.5</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">39.0</span>, <span class="number">138.0</span>, <span class="number">91.67</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">5.0</span>, <span class="number">90.0</span>, <span class="number">69.48</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">1.9</span>, <span class="number">89.0</span>, <span class="number">73.34</span>], </span></span><br><span class="line"><span class="language-javascript">	[<span class="number">52.0</span>, <span class="number">82.8</span>, <span class="number">62.27</span>]</span></span><br><span class="line"><span class="language-javascript">];</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> cities = [<span class="string">&#x27;上海&#x27;</span>, <span class="string">&#x27;湖北&#x27;</span>, <span class="string">&#x27;海南&#x27;</span>, <span class="string">&#x27;四川&#x27;</span>, <span class="string">&#x27;云南&#x27;</span>, <span class="string">&#x27;江苏&#x27;</span>, <span class="string">&#x27;陕西&#x27;</span>, <span class="string">&#x27;甘肃&#x27;</span>, <span class="string">&#x27;湖南&#x27;</span>, <span class="string">&#x27;广东&#x27;</span>, <span class="string">&#x27;重庆&#x27;</span>, <span class="string">&#x27;西藏&#x27;</span>, <span class="string">&#x27;天津&#x27;</span>, <span class="string">&#x27;青海&#x27;</span>, <span class="string">&#x27;辽宁&#x27;</span>, <span class="string">&#x27;浙江&#x27;</span>, <span class="string">&#x27;江西&#x27;</span>, <span class="string">&#x27;山西&#x27;</span>, <span class="string">&#x27;山东&#x27;</span>, <span class="string">&#x27;北京&#x27;</span>, <span class="string">&#x27;广西&#x27;</span>, <span class="string">&#x27;贵州&#x27;</span>, <span class="string">&#x27;河南&#x27;</span>, <span class="string">&#x27;安徽&#x27;</span>];</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> barHeight = <span class="number">30</span>;</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">option = &#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">title</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">text</span>: <span class="string">&#x27;到底哪些地方去得起？？&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">subtext</span>: <span class="string">&#x27;钱包允许（数据来源：爬取的去哪旅行）&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">legend</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">show</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: [<span class="string">&#x27;价格范围&#x27;</span>, <span class="string">&#x27;均值&#x27;</span>]</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">grid</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">top</span>: <span class="number">100</span></span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">angleAxis</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">type</span>: <span class="string">&#x27;category&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: cities</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">tooltip</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">show</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">formatter</span>: <span class="keyword">function</span> (<span class="params">params</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> id = params.<span class="property">dataIndex</span>;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">return</span> cities[id] + <span class="string">&#x27;&lt;br&gt;最低：&#x27;</span> + data[id][<span class="number">0</span>] + <span class="string">&#x27;&lt;br&gt;最高：&#x27;</span> + data[id][<span class="number">1</span>] + <span class="string">&#x27;&lt;br&gt;平均：&#x27;</span> + data[id][<span class="number">2</span>];</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">radiusAxis</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">polar</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">series</span>: [&#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">itemStyle</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">color</span>: <span class="string">&#x27;transparent&#x27;</span></span></span><br><span class="line"><span class="language-javascript">        &#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: data.<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">d</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">return</span> d[<span class="number">0</span>];</span></span><br><span class="line"><span class="language-javascript">        &#125;),</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">coordinateSystem</span>: <span class="string">&#x27;polar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">stack</span>: <span class="string">&#x27;最大最小值&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">silent</span>: <span class="literal">true</span></span></span><br><span class="line"><span class="language-javascript">    &#125;, &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: data.<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">d</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">return</span> d[<span class="number">1</span>] - d[<span class="number">0</span>];</span></span><br><span class="line"><span class="language-javascript">        &#125;),</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">coordinateSystem</span>: <span class="string">&#x27;polar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">name</span>: <span class="string">&#x27;价格范围&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">stack</span>: <span class="string">&#x27;最大最小值&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    &#125;, &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">itemStyle</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">color</span>: <span class="string">&#x27;transparent&#x27;</span></span></span><br><span class="line"><span class="language-javascript">        &#125;,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: data.<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">d</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">return</span> d[<span class="number">2</span>] - barHeight;</span></span><br><span class="line"><span class="language-javascript">        &#125;),</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">coordinateSystem</span>: <span class="string">&#x27;polar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">stack</span>: <span class="string">&#x27;均值&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">silent</span>: <span class="literal">true</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">z</span>: <span class="number">10</span></span></span><br><span class="line"><span class="language-javascript">    &#125;, &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">type</span>: <span class="string">&#x27;bar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">data</span>: data.<span class="title function_">map</span>(<span class="keyword">function</span> (<span class="params">d</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">return</span> barHeight * <span class="number">2</span>;</span></span><br><span class="line"><span class="language-javascript">        &#125;),</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">coordinateSystem</span>: <span class="string">&#x27;polar&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">name</span>: <span class="string">&#x27;均值&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">stack</span>: <span class="string">&#x27;均值&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">barGap</span>: <span class="string">&#x27;-100%&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">z</span>: <span class="number">10</span></span></span><br><span class="line"><span class="language-javascript">    &#125;]</span></span><br><span class="line"><span class="language-javascript">&#125;;</span></span><br><span class="line"><span class="language-javascript">;</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">if</span> (option &amp;&amp; <span class="keyword">typeof</span> option === <span class="string">&quot;object&quot;</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">    myChart.<span class="title function_">setOption</span>(option, <span class="literal">true</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;</span></span><br><span class="line"><span class="language-javascript">       </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><img src="https://s1.ax1x.com/2020/06/19/NMchon.jpg" alt="NMchon.jpg" style="zoom:76%;" /></p>
<h1 id="源代码"><a href="#源代码" class="headerlink" title="源代码"></a>源代码</h1><p><a target="_blank" rel="noopener" href="https://github.com/shimmerjordan/tourSpotList">shimmerjordan的gayhub</a></p>
<h1 id="这次一定！"><a href="#这次一定！" class="headerlink" title="这次一定！"></a>这次一定！</h1><p>关于下次一定的事情，这里我终于没有放鸽子，电脑没关爬了一下，4000多页的数据全部爬取，所生成的热力图如下所示：</p>
<p><img src="https://s1.ax1x.com/2020/06/21/N3V8RU.jpg" alt="N3V8RU.jpg"></p>
<p><img src="https://s1.ax1x.com/2020/06/21/N3V3GT.jpg" alt="N3V3GT.jpg"></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://blog.shimmerjordan.eu.org/2020/06/19/pyecharts_tour_statistic/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Python-%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96/" rel="tag">Python - 数据可视化</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Python%E7%88%AC%E8%99%AB/" rel="tag">Python爬虫</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/06/25/SpringBoot-SpringCloud/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            SpringBoot和SpringCloud
          
        </div>
      </a>
    
    
      <a href="/2020/06/17/py_csv_primary/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Python可视化csv数据实例</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "StYfTMDp78X0EltFR16ve2q5-gzGzoHsz",
    app_key: "G4RPxRpXG6RwdfpnJefOSnyy",
    path: window.location.pathname,
    avatar: "wavatar",
    placeholder: "ヾﾉ≧∀≦)o来啊，快活啊!",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
   
<!-- minivaline评论 -->
<div id="mvcomments-box">
  <div id="mvcomments"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/minivaline@latest"></script>
<script>
    new MiniValine(Object.assign({"enable":true,"mode":"DesertsP","placeholder":"Write a Comment","math":true,"md":true,"enableQQ":true,"NoRecordIP":false,"visitor":true,"maxNest":6,"pageSize":6,"adminEmailMd5":"de8a7aa53d07e6b6bceb45c64027763d","tagMeta":["管理员","小伙伴","访客"],"master":["de8a7aa53d07e6b6bceb45c64027763d"],"friends":["b5bd5d836c7a0091aa8473e79ed4c25e","adb7d1cd192658a55c0ad22a3309cecf","3ce1e6c77b4910f1871106cb30dc62b0","cfce8dc43725cc14ffcd9fb4892d5bfc"],"lang":null,"emoticonUrl":["https://cdn.jsdelivr.net/npm/alus@latest","https://cdn.jsdelivr.net/gh/MiniValine/qq@latest","https://cdn.jsdelivr.net/gh/MiniValine/Bilibilis@latest","https://cdn.jsdelivr.net/gh/MiniValine/tieba@latest","https://cdn.jsdelivr.net/gh/MiniValine/twemoji@latest","https://cdn.jsdelivr.net/gh/MiniValine/weibo@latest"]}, {
	  el: '#mvcomments',
    }));
  const infoEle = document.querySelector('#mvcomments .info');
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
      infoEle.childNodes.forEach(function (item) {
          item.parentNode.removeChild(item);
      });
  }
</script>
<style>
	#mvcomments-box {
		padding: 5px 30px;
	}
	@media screen and (max-width: 800px) {
		#mvcomments-box {
		  padding: 5px 0px;
		}
	}
	.darkmode .MiniValine *{
		color: #f1f1f1!important;
	}
	.darkmode .commentTrigger{
		background-color: #403e3e !important;
	  }
	.darkmode .MiniValine .vpage .more{
		background: #21232F
	}
	.darkmode img{
		filter: brightness(30%)
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment.expand:before{
		background: linear-gradient(180deg, rgba(246,246,246,0), rgba(0,0,0,0.9))
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment.expand:after{
		background: rgba(0,0,0,0.9)
	}
	.darkmode .MiniValine .vlist .vcard .vcomment-body .text-wrapper .vcomment pre{
		background: #282c34
		border: 1px solid #282c34
	}
	.darkmode .MiniValine .vinputs-area .textarea-wrapper textarea{
		color: #000;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper input{
		color: #000;
	}
	.darkmode .MiniValine .vinputs-area .vextra-area .vsmile-icons{
		background: transparent;
	}
	.darkmode .MiniValine .vinputs-wrap{
		border-color: #b2b2b5;
	}
	.darkmode .MiniValine .vinputs-wrap:hover{
		border: 1px dashed #2196f3;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper{
		border-bottom: 1px dashed #b2b2b5;
	}
	.darkmode .MiniValine .vinputs-area .auth-section .input-wrapper:hover{
		border-bottom: 1px dashed #2196f3;
	}
	.darkmode .MiniValine .vbtn{
		background-color: transparent!important;
	}
	.darkmode .MiniValine .vbtn:hover{
		border: 1px dashed #2196f3;
	}
</style>

    
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2024
        <i class="ri-heart-fill heart_icon"></i> 鞠桥丹-QIAODAN JU
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s4.cnzz.com/z_stat.php?id=1279035150&amp;web_id=1279035150'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="丛烨-shimmerjordan"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">Home</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">Catalogue</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">Tags</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E9%9A%8F%E7%AC%94/">Essay</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">Archives</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">Friends</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/01/18/about">About</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯蓝莓汁吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->


<script src="/js/clickLove.js"></script>


<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>